package com.xingchi.tornado.storage.core.controller;

import com.xingchi.tornado.basic.Result;
import com.xingchi.tornado.storage.core.model.dto.FileChunkCheckDTO;
import com.xingchi.tornado.storage.core.model.dto.FileChunkMergeDTO;
import com.xingchi.tornado.storage.core.model.dto.FileChunkUploadDTO;
import com.xingchi.tornado.storage.core.model.dto.FileUserRelDTO;
import com.xingchi.tornado.storage.core.model.vo.FileChunkUploadVO;
import com.xingchi.tornado.storage.core.service.FileChunkService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文件分片上传控制器
 *
 * @author xingchi
 * @date 2025-03-16 22:41
 */
@RestController
@Tag(name = "文件分片上传控制器", description = "文件分片上传控制器")
@RequestMapping("/file/chunk")
public class FileChunkController {

    @Autowired
    private FileChunkService fileChunkService;

    @Operation(summary = "校验文件分片信息", description = "校验文件分片信息")
    @GetMapping("/check")
    public Result<FileChunkUploadVO> checkChunk(@Validated FileChunkCheckDTO info) {
        return Result.ok(fileChunkService.checkChunk(info));
    }

    @Operation(summary = "上传文件分片", description = "上传文件分片")
    @GetMapping("/upload")
    public Result<FileChunkUploadVO> uploadChunk(@Validated FileChunkUploadDTO info) {
        return Result.ok(fileChunkService.uploadChunk(info));
    }

    @Operation(summary = "合并文件分片", description = "合并文件分片")
    @GetMapping("/merge")
    public Result<FileUserRelDTO> mergeChunks(@Validated FileChunkMergeDTO info) {
        return Result.ok(fileChunkService.mergeChunks(info));
    }

}
